package com.markerhub.modules.app.controller;

import com.markerhub.common.dto.HomeLableDto;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.AppBlueLabel;
import com.markerhub.entity.AppUserSetting;
import com.markerhub.modules.app.annotation.Login;
import com.markerhub.service.AppBlueLabelService;
import com.markerhub.service.AppUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


@RestController
@RequestMapping("/app")
public class UserController {
    @Resource
    AppUserService appUserService;

    @Resource
    AppBlueLabelService appBlueLabelService;



    @Login
    @GetMapping("/userInfo")
    public Result getUserInfo()  {
        AppUserSetting currentUser = appUserService.getCurrentUser();
        return Result.success(currentUser);
    }

    @GetMapping("/userInfo1")
    public Result getUserInfo1()  {
        return Result.success();
    }


    @Login
    @PostMapping("/getlabels")
    public Result getUserLables(@Validated @RequestBody HomeLableDto loginDto) {
        List<AppBlueLabel> queryLables = appBlueLabelService.getQueryLables(loginDto);
        return Result.success(queryLables);

    }


    @Login
    @PostMapping("/userInfo/getUserLables")
    public Result getUserLables(@RequestParam("userId") String userId) {
        List<AppBlueLabel> queryLables = appBlueLabelService.getQueryLabeList(userId);
        return Result.success(queryLables);

    }



    @Login
    @PostMapping("/userInfo/update")
    public Result getUserLables111(@Validated @RequestBody AppBlueLabel mAppBlueLabel) {
        AppUserSetting currentUser = appUserService.getCurrentUser();
        mAppBlueLabel.setUserId(currentUser.getId().toString());
        mAppBlueLabel.setUsername(currentUser.getUsername());
        mAppBlueLabel.setLabelTime(LocalDateTime.now());
        int update = appBlueLabelService.update(mAppBlueLabel);
        if (update>0){
            return Result.success("isOk");
        }else{
            return Result.fail("更新失败");
        }


    }



}



